package manager.qrcode;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;

import org.springframework.beans.BeansException;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import database.DBService;
import database.pojo.MachineInfo;
import service.IGetQRCode;
import util.MyFactory;
@Component("QRCodeManager")
public class QRCodeManager{
	//@Scheduled(cron = "0 0 0 * * ?")//测试环境需要注释
	public void updateQRCodes() throws Exception{
		List<MachineInfo> l1 = MyFactory.context.getBean("DBService", DBService.class).selectAllMachineInfo();
		IGetQRCode getQRCode = MyFactory.context.getBean("GetQRCode", IGetQRCode.class); 
		for (MachineInfo machineInfo : l1) {
			machineInfo.setQrCodeUrl(getQRCode.getQRCode(machineInfo.getMcahineId()));
			MyFactory.context.getBean("DBService", DBService.class).updateMachineInfo(machineInfo);
		}
	}
	
	//获取微信登录的二维码
	public String getQRCode(int machineId) throws BeansException, SQLException{
		MachineInfo m1 = MyFactory.context.getBean("DBService", DBService.class).selectMachineInfoById(machineId);
		if(null==m1) {
			return "";
		}
		return m1.getQrCodeUrl();
	}
}
